<?php

/**
 * 文章控制器
 *
 * @author 煤老板 <meok23@sina.com>
 * @date   2017-06-16
 */

namespace app\front\controller;

use app\front\model\Art;
use fw\base\Conf;
use fw\base\View;
use fw\tool\Request;

class ControllerArt extends Base
{
    public function browse()
    {
        // 参数获取
        $length = Conf::$all['front_art_length'];
        $current_page = (int)Request::get('page', null, 1);

        // 条数总计
        $list_count = Art::gi()->getList([
            'is_hide'  => 0,
            'types'    => 'art',
            'is_count' => true,
        ]);
        $page_total = ceil($list_count / $length);

        // 分页
        $option = [
            'current_page' => $current_page,
            'page_total'   => $page_total,
            'list_count'   => $list_count,
        ];
        $page = new \app\common\logic\Page($option);
        $page_show = $page->show();

        // 查询列表
        $data = Art::gi()->getList([
            'types'  => 'art',
            'length' => $length,
            'page'   => $current_page,
        ]);

        // 输出到视图
        View::render('art_browse', ['page_show' => $page_show, 'data' => $data]);
    }

    public function view()
    {
        $art_id = Request::get('art_id');
        $data = Art::gi()->getInfo(['art_id' => $art_id]);

        // 输出到视图
        View::render('art_view', ['data' => $data]);
    }
}
